home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
src.arc
/
FINGERD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-18
|
3KB
|
129 lines
/* Finger server */
#include <stdio.h>
#include <string.h>
#include "global.h"
#include "mbuf.h"
#include "socket.h"
#include "session.h"
#include "proc.h"
#include "dirutil.h"
extern char *Fdir;
static int Sfinger = -1; /* Prototype socket for service */
static void fingerd __ARGS((int s,void *unused,void *p));
/* Start up finger service */
int
finstart(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct sockaddr_in lsocket;
int s;
if(Sfinger != -1){
freeargs(argc,argv);
return 0;
}
psignal(Curproc,0); /* Don't keep the parser waiting */
chname(Curproc,"Finger listener");
lsocket.sin_family = AF_INET;
lsocket.sin_addr.s_addr = Ip_addr;
if(argc < 2)
lsocket.sin_port = IPPORT_FINGER;
else
lsocket.sin_port = atoi(argv[1]);
freeargs(argc,argv);
Sfinger = socket(AF_INET,SOCK_STREAM,0);
bind(Sfinger,(char *)&lsocket,sizeof(lsocket));
listen(Sfinger,1);
for(;;){
if((s = accept(Sfinger,NULLCHAR,(int *)NULL)) == -1)
break; /* Service is shutting down */
/* Spawn a server */
newproc("fingerd",512,fingerd,s,NULL,NULL);
}
return 0;
}
static void
fingerd(s,unused,p)
int s;
void *unused;
void *p;
{
char user[80];
FILE *fp;
struct mbuf *bp;
char *file,*cp;
int c;
sockowner(s,Curproc);
log(s,"open Finger");
recvline(s,user,80);
rip(user);
if(strlen(user) == 0){
fp = dir(Fdir,0);
if(fp == NULLFILE)
usprintf(s,"No finger information available\n");
else
usprintf(s,"Known users on this system:\n");
} else {
file = pathname(Fdir,user);
/* Check for attempted security violation (e.g., somebody
* might be trying to finger "../ftpusers"!)
*/
if(strncmp(file,Fdir,strlen(Fdir)) != 0){
fp = NULLFILE;
usprintf(s,"Invalid user name %s\n",user);
} else if((fp = fopen(file,READ_TEXT)) == NULLFILE)
usprintf(s,"User %s not known\n",user);
free(file);
}
while(fp != NULLFILE){
if((bp = alloc_mbuf(BLKSIZE+1)) == NULLBUF)
break;
cp = bp->data;
while(bp->cnt < BLKSIZE && (c = fgetc(fp)) != EOF){
switch(c){
case '\r':
continue;
case '\n':
*cp++ = '\r';
*cp++ = '\n';
bp->cnt += 2;
break;
default:
*cp++ = c;
bp->cnt++;
break;
}
}
if(bp->cnt != 0){
if(send_mbuf(s,bp,0,NULLCHAR,0) == -1)
break;
} else {
free_p(bp);
break;
}
}
if(fp != NULLFILE)
fclose(fp);
close_s(s);
log(s,"close Finger");
}
int
fin0(argc,argv,p)
int argc;
char *argv[];
void *p;
{
close_s(Sfinger);
Sfinger = -1;
return 0;
}